package com.karry.service.impl;

import com.karry.mapper.QuestionMapper;
import com.karry.pojo.Question;
import com.karry.service.QuestionService;
import com.karry.util.SqlSessionFactoryUtils;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

import java.util.List;

public class QuestionServiceImpl implements QuestionService {

    SqlSessionFactory sqlSessionFactory = SqlSessionFactoryUtils.getSqlSessionFactory();

    @Override
    public List<Question> searchAllQuestion() {
        SqlSession sqlSession = sqlSessionFactory.openSession();
        QuestionMapper mapper = sqlSession.getMapper(QuestionMapper.class);

        List<Question> list = mapper.searchAllQuestion();
        sqlSession.close();
        return list;
    }

    @Override
    public Question searchQuestionById(int id) {

        SqlSession sqlSession = sqlSessionFactory.openSession();
        QuestionMapper mapper = sqlSession.getMapper(QuestionMapper.class);

        Question question = mapper.searchQuestionById(id);
        sqlSession.close();
        return question;
    }
}
